/**
 * @file key_imei.c
 * @brief 
 * @author  ()
 * @version 1.0
 * @date 2024-11-04
 * @ingroup flash
 * @copyright Copyright (C) 2019 Queclink Wireless Solutions (ShenZhen) Co., Ltd. All Rights Reserved.
 * 
 * @par 修改日志:
 * <table>
 * <tr><th>Date       <th>Version <th>Author  <th>Description
 * <tr><td>2024-11-04 <td>1.0     <td>     <td>内容
 * </table>
 */
#include "global.h"
#define LOG_TAG   "PARM"
#include "easylog/elog.h"

#include "key_params.h"



/**
 * @brief APN存储结构
 */
typedef struct
{
    char imei[IMEI_MAX_SZIE];
    uint16_t crc;
} imei_key_params_t;

/**
 * @brief 从外挂flash读取IMEI参数
 * @param  imei             My Param doc
 * @param  imei_len         My Param doc
 * @return int32_t 
 */
int32_t load_imei(char *imei, ssize_t imei_len)
{
    imei_key_params_t key;

    if(imei_len != sizeof(imei_key_params_t))
        return -EIO;

    if (!load_key_params(DIRECT_IMEI_OFFSET, (unsigned char *)&key, sizeof(key),
                         offsetof(imei_key_params_t, crc)))
    {
        log_e("load apn failed!\r\n");
        return 1;
    }

    memcpy(imei, &key.imei, strlen(key.imei));

    return 0;
}


/**
 * @brief 保存IMEI到外挂Flash的第一扇区
 * @param  imei             My Param doc
 * @return int32_t 
 */
int32_t save_quec_imei(char *imei)
{
    // imei_key_params_t key;

    // memcpy(key.imei, (char *)imei, strlen(imei));
    // save_key_params(DIRECT_IMEI_OFFSET, (unsigned char *)&key, sizeof(key),
    //                 offsetof(imei_key_params_t, crc));
    
    return 0;
}
